/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads.client.communication;

import core.messages.Msg;
import core.messages.server.inGame.Msg_Card_Cast_Continue;
import core.messages.server.inGame.舍弃版本_Msg_Card_Drop_Insuff;
import core.messages.server.inGame.Msg_Duel_Continue;
import core.messages.server.inGame.Msg_Response_Accept;
import core.messages.server.inGame.Msg_Turn_Begin;
import core.threads.DataBase;
import core.threads.client.Client_Public_Data;
import core.threads.client.Client_Public_MsgBox;
import core.threads.client.Client_Public_Thread;
import core.threads.client.inGame.T_Client_Cast_Phase;
import core.threads.client.inGame.T_Client_Drop_Phase;
//import core.threads.client.inGame.T_Client_Duel;
import core.threads.client.inGame.T_Client_Judge_Phase;
import core.threads.client.inGame.T_Client_Responser;
import cstAndEnum.SKILL_TYPE;

/**
 *
 * @author Invince
 */
public class 舍弃版本_T_Client_Msg_Handler_Copy  extends Thread{
/*----------Attributs-------------------*/
    protected boolean stop;
    protected boolean suspend;
/*----------Public functions------------*/
    @Override
    public void run() {
        /**-----Init-----**/
        /**-----Loop----**/
        while(!this.stop){
            if(!this.suspend){
                if(!Client_Public_MsgBox.msgBox_Client_Rcv_Msg.isEmpty()){
                    Msg msg=Client_Public_MsgBox.msgBox_Client_Rcv_Msg.poll();
                    if(msg instanceof Msg_Turn_Begin){
                        Client_Public_Thread.tClientJudgePhase=new T_Client_Judge_Phase();
                        Client_Public_Thread.tClientJudgePhase.start();
                    }else if(msg instanceof Msg_Card_Cast_Continue){
                        Client_Public_Thread.tClientCastPhase=new T_Client_Cast_Phase();
                        Client_Public_Thread.tClientCastPhase.start();
                    }else if(msg instanceof 舍弃版本_Msg_Card_Drop_Insuff){
                        Client_Public_Data.myTurnBegin();//重开自己的turn
                        Client_Public_Thread.tClientDropPhase=new T_Client_Drop_Phase();
                        Client_Public_Thread.tClientDropPhase.start();
                    }else if(msg instanceof Msg_Response_Accept){//包含被出决斗
                        Msg_Response_Accept msgResponseAccept=(Msg_Response_Accept) msg;
                        int idCard=msgResponseAccept.getIdCard();
                        int idSkill=msgResponseAccept.getIdSkill();
                        int idSource=msgResponseAccept.getIdSource();
                        int[] idTargets=msgResponseAccept.getIdTargetPlayers();
                        SKILL_TYPE skillType=msgResponseAccept.getSkillType();
                        Client_Public_Thread.tClientResponse=new T_Client_Responser(idSkill, idSource, idTargets, idCard, skillType);
                        Client_Public_Thread.tClientResponse.start();
                    }else if(msg instanceof Msg_Duel_Continue){//注意这里是继续决斗，决斗在上面
                        Msg_Duel_Continue msgDuelContinue=(Msg_Duel_Continue) msg;
                        int idCard=-1;//-1都是没用的东西
                        int idSkill=DataBase.findSkillByName("继续决斗").getId();
                        int idSource=msgDuelContinue.getIdSource();
                        int[] idTargets={msgDuelContinue.getIdTarget()};
                        SKILL_TYPE skillType=SKILL_TYPE.NORMAL_SKILL;
                        Client_Public_Thread.tClientResponse=new T_Client_Responser(idSkill, idSource, idTargets, idCard, skillType);
                        Client_Public_Thread.tClientResponse.start();
//                        Client_Public_Thread.tClientDuel=new T_Client_Duel(idSource, idTarget);
//                        Client_Public_Thread.tClientDuel.start();
                        //？？？？？？？？？？？？？？？？底下的部分有可能删掉
                    }//else if(msg instanceof Msg_Response_End){
//                        Client_Public_Thread.tClientResponse.stop();//？？？？？？？？？，stopT方法写下
//                    }else if(msg instanceof Msg_Duel_End){
//                        Client_Public_Thread.t
//                    }

                }
            }
        }
        /**----End-----**/
    }

    public void stopT(){
        synchronized(this){
            this.stop=true;
        }
    }

    public void suspendT(){
        synchronized(this){
            this.suspend=true;
        }
    }

    public void resumeT(){
        synchronized(this){
            this.suspend=false;
        }
    }
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
    public 舍弃版本_T_Client_Msg_Handler_Copy() {
        synchronized(this){
            this.stop=false;
            this.suspend=false;
        }
    }
/*----------Gets and sets---------------*/

}
